package _aliyun.elasticsearch.test;

import com.aliyuncs.CommonRequest;
import com.aliyuncs.CommonResponse;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.exceptions.ServerException;
import com.aliyuncs.http.FormatType;
import com.aliyuncs.http.MethodType;
import com.aliyuncs.profile.DefaultProfile;

public class ListSearchLog {

    public static final String regionId = "cn-hangzhou";
    public static final String domain = "elasticsearch.cn-hangzhou.aliyuncs.com";
    public static final String instanceId = "es-cn-j6731edsu000l30jv";
    public static final String accessKeyId = "LTAIW47wcDVHpci1";
    public static final String accessSecret = "FkwiXtCSK1xpAQeMOIDBAW0Tv3Uoc8";
    public static final String version = "7.10.0";
    public static final String public_url = "es-cn-j6731edsu000l30jv.public.elasticsearch.aliyuncs.com";
    public static final String public_port = "9200";

    public static void main(String[] args) {
        DefaultProfile profile = DefaultProfile.getProfile(regionId, accessKeyId, accessSecret);
        IAcsClient client = new DefaultAcsClient(profile);

        CommonRequest request = new CommonRequest();
        //request.setProtocol(ProtocolType.HTTPS);
        request.setMethod(MethodType.GET);
        request.setDomain(domain);
        request.setVersion("2017-06-13");
        request.setUriPattern("/openapi/instances/es-cn-j6731edsu000l30jv/search-log");
        request.putQueryParameter("type", "INSTANCELOG");
        request.putQueryParameter("query", "level:warn");
        request.putQueryParameter("beginTime", "1593332477000");
        request.putQueryParameter("endTime", String.valueOf(System.currentTimeMillis()));
        request.putQueryParameter("page", "1");
        request.putQueryParameter("size", "20");
        request.putHeadParameter("Content-Type", "application/json");
        String requestBody = "" +
                "{}";
        request.setHttpContent(requestBody.getBytes(), "utf-8", FormatType.JSON);
        try {
            long t1 = System.currentTimeMillis();
            CommonResponse response = client.getCommonResponse(request);
            long cost = System.currentTimeMillis()-t1;
            System.out.println(cost);
            System.out.println(response.getData());
        } catch (ServerException e) {
            e.printStackTrace();
        } catch (ClientException e) {
            e.printStackTrace();
        }
    }
}